package com.gx.service.impl;


import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gx.common.exception.CommonException;
import com.gx.mapper.ActHiCommentMapper;
import com.gx.model.dto.definition.FileMsgDto;
import com.gx.model.dto.definition.FlowCommentDto;
import com.gx.model.dto.definition.UpdateActCommentDto;
import com.gx.model.pojo.ActHiComment;
import com.gx.service.FlowCommentService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author lpj
 * @description 流程补录操作
 * @createDate 2022-03-09 19:00:25
 */
@Service
public class FlowCommentServiceImpl extends ServiceImpl<ActHiCommentMapper, ActHiComment> implements FlowCommentService {

    @Override
    public ActHiComment upDateTaskCommentById(UpdateActCommentDto param) {
        String taskId = param.getTaskId();
        String insId = param.getInsId();
        List<FileMsgDto> url = param.getUrl();
        String message = param.getMessage();
        FlowCommentDto commentDto = new FlowCommentDto();
        commentDto.setMessage(message);
        commentDto.setUrl(url);
        String fullMsg = JSONObject.toJSONString(commentDto);
        LambdaQueryWrapper<ActHiComment> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(ActHiComment::getProcInstId, insId)
                .eq(ActHiComment::getTaskId, taskId)
                .eq(ActHiComment::getAction, "AddComment");
        ActHiComment actHiComment = this.getOne(wrapper);
        if (actHiComment == null) {
            throw new CommonException("自动审批节点不可进行补录");
        }
        actHiComment.setFullMsg(fullMsg);
        actHiComment.setMessage(fullMsg);
        this.updateById(actHiComment);
        return actHiComment;
    }
}




